#include "default_signal.h"

namespace nsi {
namespace spike {

default_signal::default_signal(int value)
  : signal_base(),
    value_(value)
{

}

default_signal::default_signal(const default_signal& other)
  : signal_base(other),
    value_(other.value_)
{

}

default_signal::~default_signal()
{

}

default_signal& default_signal::operator=(const default_signal& other)
{
  signal_base::operator=(other);
  value_ = other.value_;
  return *this;
}

bool default_signal::create()
{
  return sigaction(value_, 0, &action_) >= 0;
}

bool default_signal::operator()(default_signal::signal_info_type* info,
  void* ucontext)
{
  action_type default_action;
  // Clear actions mask
  sigemptyset(&default_action.sa_mask);
  default_action.sa_flags = 0;
  default_action.sa_handler = SIG_DFL;
  default_action.sa_sigaction = 0;

  // Set the default action
  sigaction(value(), &default_action, 0);
  // Reraise the signal with the default action
  raise(value());
  return true;
}

} // namespace spike
} // namespace nsi
